class ParDefParser extends TreeParser;

options {
	importVocab = Java;
}

{

    public String getParName() {
        return _parName;
    }
    
    public int getNarray() {
         return _ntypeArray;
    }

    public String getCurrentPar() {
        return _currentPar.toString();
    }

    public String getTypeName() {
        return _typeName;
    }

    private StringBuffer _currentPar;    
    private int _ntypeArray;
    private String _typeName;
    private StringBuffer _currentModifiers;
    private StringBuffer _currentID;
    
    private String _parName = null;
    private boolean _isArray = false;   
}

parameterDef    { _currentPar = new StringBuffer(); }
	:	#(PARAMETER_DEF 
	            modifiers { _currentPar.append(_currentModifiers.toString()); }
	            typeSpec {
		        _currentPar.append(_typeName + " ");
		        for(int i = 0;i < _ntypeArray;i++) {
			    _currentPar.append("[]");
			}
			_currentPar.append(" ");
		    }
		    n1:IDENT { _currentPar.append(n1.getText()); _parName = n1.getText(); } )
	;

modifiers   { _currentModifiers = new StringBuffer(); }
	:	#( MODIFIERS (n1:modifier { _currentModifiers.append(n1.getText() + " "); } )* )    
	;

modifier
    :   "private"
    |   "public"
    |   "protected"
    |   "static"
    |   "transient"
    |   "final"
    |   "abstract"
    |   "native"
    |   "threadsafe"
    |   "synchronized"
    |   "const"
    |   "volatile"
	|	"strictfp"
    ;

typeSpec        { _ntypeArray = 0; }
	:	#(TYPE typeSpecArray)
	;

typeSpecArray   
	:	#( ARRAY_DECLARATOR { _ntypeArray++; } typeSpecArray { _isArray = true; } )
	|	type
	;

type:	identifier 		{ _typeName = _currentID.toString(); }
	|	n1:builtInType	{ _typeName = n1.getText(); }
	;

identifier    { _currentID = new StringBuffer(); } 
	:	x:IDENT  		    { _currentID.append(x.getText()); }
	|	#( DOT identifier y:IDENT ) { _currentID.append("." + y.getText()); }
	;

builtInType
    :   "void"
    |   "boolean"
    |   "byte"
    |   "char"
    |   "short"
    |   "int"
    |   "float"
    |   "long"
    |   "double"
    ;
